﻿
#if MAPEDITOR
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using FolderData;

namespace Folder
{
    public partial class MapInfo : Form
    {
        Map map;
        public MapInfo()
        {
            InitializeComponent();
        }

        public void SetData(Map map)
        {
            this.map = map;
            mapNameTextBox.Text = map.Name;
            playerAssetNameTextBox.Text = map.PlayerAssetName;
            propertyGrid1.SelectedObject = map.PlayerDataSet;
            mapSizeXTextBox.Text = Convert.ToString(map.MapSize.X);
            mapSizeYTextBox.Text = Convert.ToString(map.MapSize.Y);
            mapSizeWTextBox.Text = Convert.ToString(map.MapSize.Width);
            mapSizeHTextBox.Text = Convert.ToString(map.MapSize.Height);
            bgAssetNameTextBox.Text = map.BgAssetName;
        }

        private void MapInfo_FormClosing(object sender, FormClosingEventArgs e)
        {
            int mapX, mapY, mapW, mapH;
            mapX = int.Parse(mapSizeXTextBox.Text);
            mapY = int.Parse(mapSizeYTextBox.Text);
            mapW = int.Parse(mapSizeWTextBox.Text);
            mapH = int.Parse(mapSizeHTextBox.Text);
            if (mapW <Camera.SCREEN_WIDTH)
            {
                MessageBox.Show(string.Format("맵의 Width는 화면의 Width({0})보다 작을 수 없습니다.", Camera.SCREEN_WIDTH), "FolderMapEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                mapSizeWTextBox.Focus();
                mapSizeWTextBox.SelectAll();
                return;
            }
            if (mapH < Camera.SCREEN_HEIGHT)
            {
                MessageBox.Show(string.Format("맵의 Height는 화면의 Height({0})보다 작을 수 없습니다.", Camera.SCREEN_HEIGHT), "FolderMapEditor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                mapSizeHTextBox.Focus();
                mapSizeHTextBox.SelectAll();
                return;
            }

            map.Name = mapNameTextBox.Text;
            try
            {
                map.Background = Session.ScreenManager.Game.Content.Load<MapBackground>(bgAssetNameTextBox.Text);
                map.Background.LoadContent(Session.ScreenManager.Game.Content);
            }
            catch
            {
                MessageBox.Show("해당 BG Asset를 부를 수 없어 맵의 Background가 null로 세팅됩니다.");
                map.Background = null;
            }
            map.PlayerDataSet.Name = playerAssetNameTextBox.Text;
            map.MapSize = new Microsoft.Xna.Framework.Rectangle(mapX, mapY, mapW, mapH);
            map.BgAssetName = bgAssetNameTextBox.Text;
        }
    }
}

#endif